home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98a.txt / 000053_icon-group-sender _Tue Feb 24 13:03:47 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  5KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id NAA05066
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Tue, 24 Feb 1998 13:03:47 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA28149; Tue, 24 Feb 1998 13:03:46 -0700
  7. Date: Tue, 24 Feb 1998 09:02:13 -0800
  8. From: kwalker@sfo.harbinger.com (Ken Walker)
  9. Message-Id: <199802241702.JAA12855@varda.premenos.com>
  10. To: icon-group@optima.CS.Arizona.EDU, khemlann@agcs.com
  11. Subject: Re: icon questions
  12. Cc: khemlann@agcs.com
  13. Mime-Version: 1.0
  14. Content-Type: text/plain; charset=us-ascii
  15. Content-Transfer-Encoding: 7bit
  16. Content-Md5: S1D7bHFkzLcfAXlHKsMdjg==
  17. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  18. Status: RO
  19. Content-Length: 4424
  20.  
  21. > Date: Tue, 17 Feb 1998 00:26:47 -0700
  22. > From: khemlann@agcs.com (Neil Khemlani)
  23. > Actually, I have two main questions.  First, is there a flag that I can
  24. > use with iconx or iconc that will allow it to produce C source code?
  25.  
  26. The -c option of iconc will produce C source code. However, the source
  27. code is only suitable for compiling and linked to a run-time system. It
  28. is not meant for human consumption. As an example, I translated
  29. a simple "hello, world" program. It produced two files. The .h file
  30. is
  31.  
  32.     /*ICONC*/
  33.     /*
  34.      * Tue Feb 24 08:12:11 1998
  35.      * This file was produced by
  36.      *   iconc: Icon Compiler Version 9.0.  July 16, 1994
  37.      */
  38.     #define COMPILER 1
  39.     #include "/home/users/edison/kwalker/icon_v9.0/bin_solaris/rt.h"
  40.     #define OpTblSz 1
  41.     int op_tbl_sz = 0;
  42.     
  43.     #define NGlobals 1
  44.     int n_globals = 0;
  45.     
  46.     int n_statics = 0;
  47.     struct descrip statics[1];
  48.     
  49.     int F291_write Params((word status , FILE *f , dptr x , int nargs , dptr 
  50. rslt));
  51.     hidden int P000_main Params((noargs));
  52.     
  53.     struct PF000_main {
  54.        struct p_frame *old_pfp;
  55.        dptr old_argp;
  56.        dptr rslt;
  57.        continuation succ_cont;
  58.        struct {
  59.           struct tend_desc *previous;
  60.           int num;
  61.           struct descrip d[1];
  62.           } tend;
  63.        };
  64.  
  65. and the .c file is
  66.  
  67.     /*ICONC*/
  68.     /*
  69.      * Tue Feb 24 08:12:11 1998
  70.      * This file was produced by
  71.      *   iconc: Icon Compiler Version 9.0.  July 16, 1994
  72.      */
  73.     #include "t1.h"
  74.     
  75.     static B_IProc(2) init_op_tbl[OpTblSz];
  76.     
  77.     static struct {word dword; union block *vword;} init_globals[NGlobals] = {
  78.        {D_Null} /* place holder */
  79.        };
  80.     
  81.     struct sdescrip init_gnames[1];
  82.     
  83.     struct b_proc *builtins[1];
  84.     
  85.     int main(argc, argv)
  86.     int argc;
  87.     char **argv;
  88.        {
  89.        op_tbl = (struct b_proc *)init_op_tbl;
  90.        globals = (dptr)init_globals;
  91.        eglobals = &globals[0];
  92.        gnames = (dptr)init_gnames;
  93.        egnames = &gnames[0];
  94.        estatics = &statics[0];
  95.        debug_info = 0;
  96.        line_info = 0;
  97.        err_conv = 0;
  98.        largeints = 0;
  99.        init(*argv, &argc, argv, 0);
  100.     
  101.        tend = NULL;
  102.        P000_main();
  103.        
  104.        c_exit(NormalExit);
  105.        }
  106.     
  107.     static int P000_main()
  108.     {
  109.        struct PF000_main r_frame;
  110.        register int r_signal;
  111.        int i;
  112.     
  113.        r_frame.old_pfp = pfp;
  114.        pfp = (struct p_frame *)&r_frame;
  115.        r_frame.old_argp = argp;
  116.        r_frame.rslt = NULL;
  117.        r_frame.succ_cont = NULL;
  118.     
  119.        for (i = 0; i < 1; ++i)
  120.           r_frame.tend.d[i] = nulldesc;
  121.        argp = NULL;
  122.        r_frame.tend.num = 1;
  123.        r_frame.tend.previous = tend;
  124.        tend = (struct tend_desc *)&r_frame.tend;
  125.     
  126.        Poll();
  127.        r_frame.tend.d[0].vword.sptr = "hello, world";
  128.        r_frame.tend.d[0].dword = 12;
  129.        Poll();
  130.        Poll();
  131.        {
  132.        FILE *f = NULL; 
  133.        word status = 
  134.     k_output.status; 
  135.        if ((k_output.status & Fs_Write) == 0 )
  136.           goto L1 /* within: write */;
  137.        f= k_output.fd;
  138.     
  139.        goto L2 /* within: write */;
  140.     L1: ; /* within: write */
  141.        err_msg(213, NULL);
  142.     
  143.     L2: ; /* within: write */
  144.        F291_write(status, f, (&r_frame.tend.d[0]), 1, &trashcan);
  145.        }
  146.        Poll();
  147.        tend = r_frame.tend.previous;
  148.        pfp = r_frame.old_pfp;
  149.        argp = r_frame.old_argp;
  150.        return A_Resume;
  151.        }
  152.  
  153. More complex programs only get worse...
  154.  
  155. There are several problems with translating Icon into C. Some of
  156. the major problems are:
  157.  
  158.    - you must implement goal-directed evaluation in a laguage
  159.      that has none. In some cases, with enough optimization, it
  160.      can be converted into loops. But in other cases the best
  161.      technique we have come up with involves breaking the program
  162.      into lots of little functions and passing function pointers
  163.      around everywhere. This is not your typical C code.
  164.      
  165.    - variables must be able to hold any value, and values must include
  166.      type information. In some cases, if you do enough analysis, you
  167.      can remove these requirements, but in general you cannot.
  168.      
  169.    - variables have to be implemented in such as way that the garbage
  170.      collector can find them.
  171.  
  172. Converting Icon programs into C is much more interesting than it
  173. appears on the surface :-)
  174.  
  175. Ken Walker, kwalker@sfo.harbinger.com
  176. Harbinger Coporation, Concord, Ca. 94520
  177.  
  178.